﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using NHibernate;

namespace Com.CMS263.DAO
{
    public  class SurveyDAO:BaseService 
    {

        public bool Add(Survey sur)
        {
            try
            {
                DBHelper.TransInsert(sur);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public void Delete(SurveyDAO sur)
        {
            DBHelper.TransDelete(sur);
        }
        public void Delete(int id)
        {
            DBHelper.TransDeleteByID("Survey", id);
        }
        #region 查询所有list
        /// <summary>
        /// 查询所有list
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<Survey> GetAll(int page ,int pagesize)
        {
            try
            {
                return DBHelper.ExecuteHQL("from Survey order by AddDate desc ").SetFirstResult((page - 1) * pagesize).SetMaxResults(pagesize).List<Survey>();
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 查询所有调查总数
        /// <summary>
        /// 查询所有调查总数
        /// </summary>
        /// <returns></returns>
        public int GetAll()
        {
            try
            {
                string hql = "select count(*) from Survey ";
                return Convert.ToInt32(GetValue(hql));
            }
            catch
            {
                return 0;
            }
        }
        #endregion
    }
}
